package com.gin.kotlin.gf2gamecommunity.network.gitee.response

import com.fasterxml.jackson.annotation.JsonAlias
import java.time.ZonedDateTime

/**
 * 发布版本信息
 * @property assets 附件
 * @property body 正文
 * @property createdAt 创建时间
 * @property id id
 * @property name 名称
 * @property preRelease 是否为预览版
 * @property tagName tag名称
 * @constructor
 */
class AppRelease(
    var assets: List<Asset> = listOf(),
    var body: String = "",
    @set: JsonAlias("created_at")
    var createdAt: ZonedDateTime = ZonedDateTime.now(),
    var id: Int = 0,
    var name: String = "",
    @set: JsonAlias("prerelease")
    var preRelease: Boolean = false,
    @set: JsonAlias("tag_name")
    var tagName: String = "",
) {
    /**
     * 获取下载地址
     * @return String?
     */
    fun obtainUrl() = assets.firstOrNull { it.url?.endsWith("apk") == true }?.url

    /**
     * 文件名
     * @return String?
     */
    fun obtainFilename() = obtainUrl()?.split("/")?.lastOrNull()

    /**
     * 附件
     * @property url 下载地址
     * @property name 名称
     */
    class Asset(
        @set: JsonAlias("browser_download_url")
        var url: String? = null,
        var name: String? = null,
    )
}
